package sk.vasicek.drinkmanager.domain;

import java.util.Locale;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public enum Language {
	AUTO(0, ""), EN(1, "en"), EN_US(11, "en-US"), EN_GB(12, "en-GB"), SK(3, "sk"), CZ(4, "cs"), DE(2, "de"), RU(5, "ru");

	private String code;

	private Language(Integer id, String code) {
		this.code = code;
	}

	public String getCode() {
		return code;
	}

	public static Locale getCodeById(Integer id) {
		switch (id) {
		case 1:
			return new Locale(EN.getCode());
		case 11:
			String[] langUS = EN_US.getCode().split("-");
			return new Locale(langUS[0], langUS[1]);
		case 12:
			String[] langGB = EN_GB.getCode().split("-");
			return new Locale(langGB[0], langGB[1]);
		case 2:
			return new Locale(DE.getCode());
		case 3:
			return new Locale(SK.getCode());
		case 4:
			return new Locale(CZ.getCode());
		case 5:
			return new Locale(RU.getCode());
		default:
			return new Locale("");
		}
	}

	public static Locale getApplicationLanguage(Context context) {
		Integer id;
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
		id = Integer.parseInt(prefs.getString("LangPref", "0"));
		if (id != null)
			if (id == 0)
				return context.getResources().getConfiguration().locale;
			else
				return getCodeById(id);
		else
			return new Locale("");
	}
}
